<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>网站后台管理模版</title>
    <link rel="stylesheet" type="text/css"
          href="assets/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="assets/admin/css/admin.css"/>
</head>

<body>
<div class="page-content-wrap" id="studentSearch">
    <h5 style="text-align:center;font-size: 20px;line-height: 25px;color:#666">学生信息管理界面</h5>
    <hr>
    <div class="layui-form-item">
        <div class="layui-inline tool-btn">
            <button class="layui-btn layui-btn-small site-demo-active"
                    data-type="tabAdd">
                <i class="layui-icon">&#xe654;</i>
            </button>
            <!-- 				<button
                                class="layui-btn layui-btn-small layui-btn-warm listOrderBtn hidden-xs"
                                data-url="/admin/category/listorderall.html">
                                <i class="iconfont">&#xe656;</i>
                            </button> -->
        </div>
        <div class="layui-inline">
            <input type="text" id="studentNameSearch" placeholder="请输入学生姓名"
                   autocomplete="off" class="layui-input">
        </div>
        <button class="layui-btn layui-btn-normal site-demo-active"
                data-type="search" id="searchStudent">搜索
        </button>
        <table class="layui-table"
               lay-data="{ url:'/student/getAllStudent', page:true, id:'idTest'}"
               lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{type:'checkbox', }"></th>
                <th lay-data="{field:'studentNo',sort: true}">学号</th>
                <th lay-data="{field:'studentName'}">姓名</th>
                <th lay-data="{field:'studentSex'}">性别</th>
                <th lay-data="{field:'stuAge'}">年龄</th>
                <th lay-data="{field:'stuBirthday'}">出生日期</th>
                <th
                        lay-data="{fixed: 'right', width:220, align:'left', toolbar: '#barDemo'}"></th>
            </tr>
            </thead>
        </table>
    </div>


    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
    </script>
    <hr></hr>
    <h5 style="text-align: center;">@学生成绩管理系统</h5>
</div>
<script src="assets/js/jquery-3.3.1.min.js"></script>
<script src="assets/admin/js/login-interceptor.js"></script>
<script src="assets/admin/layui/layui.all.js" type="text/javascript"
        charset="utf-8"></script>
<script>
    layui.use('table', function () {
        var $ = layui.jquery
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demo)', function (obj) {
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                var detailFrom = layui.layer.open({
                    title: "查看学生信息",
                    type: 2,
                    content: "/studentDetail.html",//弹出层页面
                    area: ['500px', '200px'],
                    success: function (layero, index) {
                        var body = layui.layer.getChildFrame('body', index);
                        body.find("#studentNo").text(data.studentNo);
                        body.find("#studentName").text(data.studentName);
                        body.find("#studentSex").text(data.studentSex);
                        body.find("#stuAge").text(data.stuAge);
                        body.find("#stuBirthday").text(data.stuBirthday);
                    }
                });
            }
            if (obj.event === 'del') {
                layer.confirm('真的删除该学生吗？', function (index) {
                    var data = obj.data;
                    $.ajax({
                        //几个参数需要注意一下
                        type: "POST",//方法类型
                        dataType: "json",//预期服务器返回的数据类型
                        url: "/student/deleteStudent",//url
                        data: data,
                        success: function (result) {
                            if (result.code == "0") {
                                layer.close(index);
                                layer.msg('删除学生成功');
                                layui.table.reload('idTest', {page: {curr: 1}});
                            } else {
                                layer.msg('删除学生失败', {
                                    icon: 5
                                });
                            }
                        },
                        error: function () {
                            layer.msg('服务器错误', {
                                icon: 5
                            });
                        }
                    });
                });
            }
            if (obj.event === 'edit') {
                var editFrom = layui.layer.open({
                    title: "编辑学生信息",
                    type: 2,
                    content: "/studentEdit.html",//弹出层页面
                    area: ['800px', '400px'],
                    success: function (layero, index) {
                        var body = layui.layer.getChildFrame('body', index);
                        //获取窗口对象
                        var iframeWindow = layero.find('iframe')[0].contentWindow;
                        body.find("#studentNo").val(data.studentNo);
                        body.find("#studentName").val(data.studentName);
                        body.find(".studentSex option[value=" + data.studentSex + "]").attr("selected", "selected");
                        body.find("#stuAge").val(data.stuAge);
                        body.find("#stuBirthday").val(data.stuBirthday);
                        iframeWindow.layui.form.render();
                        iframeWindow.layui.form.render('select');
                    }
                });
            }
        });

        //触发事件
        var active = {
            tabAdd: function () {

                layer.open({
                    type: 2,
                    title: '添加学生信息',
                    shadeClose: true,
                    shade: false,
                    /*    maxmin: true,  *///开启最大化最小化按钮
                    area: ['800px', '400px'],
                    content: '/studentAdd.html'
                });

            }, search: function () {
                var name = $("#studentNameSearch").val();
                table.reload('idTest', {
                    method: 'POST'
                    , where: {"studentName": name}, page: {
                        curr: 1 //重新从第 1 页开始
                    }

                })
            }
        };

        $('#studentSearch .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>
</body>

</html>